<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      img {
        position: absolute;
        top: 0;
        left: 0;
        width: 230px;
        height: 230px;
      }
    </style>
  </head>
  <body>
    <img src="./img/longmao.webp" alt="" />

    <script>
      var imgEle = document.getElementsByTagName('img');
      //得到样式表赋值
      var pointEle = getComputedStyle(imgEle[0], null);

      console.log(parseFloat(pointEle.width));
      window.onmousemove = function (event) {
        var X = event.clientX;
        var Y = event.clientY;
        //图片定位       parseInt(pointEle.width) 将字符串转为数字
        imgEle[0].style.left = X - parseInt(pointEle.width) / 2 + 'PX';

        imgEle[0].style.top = Y - parseInt(pointEle.height) / 2 + 'PX';
      };
    </script>
  </body>
</html>
